package com.smart.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smart.model.domain.ProjectFileTaskInstanceDO;
import com.smart.model.request.ProjectFileTaskInstanceRequest;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zhanghong
 */
@Repository
public interface ProjectFileTaskInstanceMapper extends BaseMapper<ProjectFileTaskInstanceDO> {
    ProjectFileTaskInstanceDO selectDOById(Long id);
    List<ProjectFileTaskInstanceDO> selectDOList(ProjectFileTaskInstanceDO projectFileTaskInstance);
    int insertDO(ProjectFileTaskInstanceDO projectFileTaskInstance);
    int batchInsertDO(List<ProjectFileTaskInstanceDO> projectFileTaskInstanceDOList);
    int updateDO(ProjectFileTaskInstanceDO projectFileTaskInstance);
    int deleteDOById(Long id);
    int deleteDOByIds(String[] ids);

    @Select({"<script>",
            "   select count(1) from project_file_task_instance i",
            "   inner join project_file_task t on t.id=i.task_id",
            "   <where>",
            "       i.deleted=0",
            "       <if test=\"param.projectId!=null\">",
            "           and i.project_id=#{param.projectId}",
            "       </if>",
            "       <if test=\"param.keyWord!=null and param.keyWord!=''\">",
            "           and (t.file_name like concat('%',#{param.keyWord},'%') or t.file_code like concat('%',#{param.keyWord},'%'))",
            "       </if>",
            "       <if test=\"param.status!=null\">",
            "           and i.status=#{param.status}",
            "       </if>",
            "   </where>",
            "</script>"})
    long pageCount(@Param("param") ProjectFileTaskInstanceRequest param);
    @Select({"<script>",
            "   select i.* from project_file_task_instance i",
            "   inner join project_file_task t on t.id=i.task_id",
            "   <where>",
            "       i.deleted=0",
            "       <if test=\"param.projectId!=null\">",
            "           and i.project_id=#{param.projectId}",
            "       </if>",
            "       <if test=\"param.keyWord!=null and param.keyWord!=''\">",
            "           and (t.file_name like concat('%',#{param.keyWord},'%') or t.file_code like concat('%',#{param.keyWord},'%'))",
            "       </if>",
            "       <if test=\"param.status!=null\">",
            "           and i.status=#{param.status}",
            "       </if>",
            "   </where>",
            "   order by status asc, create_time desc limit #{limit} offset #{offset}",
            "</script>"})
    List<ProjectFileTaskInstanceDO> pageQuery(@Param("param") ProjectFileTaskInstanceRequest param, @Param("limit") int limit, @Param("offset") long offset);
}
